import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layouts/BasicLayout'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
}

const routes = [
  {
    path: '/',
    name: 'Login',
    component: () => import(/* webpackChunkName: 'login' */ '../views/login/index.vue')
  },
  {
    path: '/hms',
    name: 'hms',
    meta: {
      title: '医院管理'
    },
    component: Layout,
    redirect: '/hms/hospital',
    children: [
      {
        path: 'hospital',
        name: 'hospital',
        meta: {
          title: '医院列表管理'
        },
        component: () => import('@/views/hms/hospital.vue')
      },
      {
        path: 'office',
        name: 'office',
        meta: {
          title: '科室管理'
        },
        component: () => import('@/views/hms/office.vue')
      },
      {
        path: 'doctor',
        name: 'doctor',
        meta: {
          title: '医生管理'
        },
        component: () => import('@/views/hms/doctor.vue')
      },
      {
        path: 'doctorDetail',
        name: 'doctorDetail',
        component: () => import('@/views/hms/doctorDetail.vue')
      }
    ]
  },
  {
    path: '/pms',
    name: 'pms',
    meta: {
      title: '患者管理'
    },
    component: Layout
  },
  {
    path: '/ams',
    name: 'dms',
    meta: {
      title: '审核管理'
    },
    component: Layout
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
